{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "eb20a0d2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.b4025238ae1b738c06bdc69638980a71.315360000.1965050990.282335-25863644', 'expires_in': 2592000, 'session_key': '9mzdCXcbnUfefEzDjjjAlZu3AKGU8ApsoeRHHfa4IK2w84RKpcQW2ynRf81A4Kcf9ec8z9iXhpBR99ps0WoV2o6OzopjyA==', 'access_token': '24.2a001670fa2892da6c273e9d82f36698.2592000.1652282990.282335-25863644', 'scope': 'public brain_all_scope vis-faceverify_faceverify_h5-face-liveness vis-faceverify_FACE_V3 vis-faceverify_idl_face_merge vis-faceverify_FACE_EFFECT vis-faceverify_face_beauty vis-faceverify_face_feature_sdk brain_face_scene_scope wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online', 'session_secret': 'a021dd54b605f41a9627bff104d423c5'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?'\n",
    "payload = {\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'B7Hoh8trKqK2j637DHVtxgei',\n",
    "    'client_secret':'zEq6KU3cGtfuVK6A6DAEFPr9zqjWqoSi',\n",
    "    \n",
    "\n",
    "}\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "58f55825",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.2a001670fa2892da6c273e9d82f36698.2592000.1652282990.282335-25863644'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.json()['access_token']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "fe6b4611",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.2a001670fa2892da6c273e9d82f36698.2592000.1652282990.282335-25863644'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "luochen_AT = response.json()['access_token']\n",
    "luochen_AT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98ea02bf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "146f9430",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e44e892b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc4f8e8d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "487925b0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c38d23af",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 作业"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "c7d8000f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.49a07f6e8a11e0e501b782ce4e0b5f81.315360000.1965052919.282335-25947206', 'expires_in': 2592000, 'session_key': '9mzdA5mJ8M85d5Py1vgEd6JRAaOApu7luaQv0UWWjgf5SlADtFWv7i7d9U9nAzLAT2UBqnq4hUsabU6V/GaiwmJ6lMkTOg==', 'access_token': '24.832a536d7e38a4339fe60f8822b0bbc8.2592000.1652284919.282335-25947206', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online', 'session_secret': 'bf75b32053f34ce63aaa2af628e606fb'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?'\n",
    "payload = {\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'TrdFp11TGxtah65HUc7ydunX',\n",
    "    'client_secret':'7EznW2kMatKutRnMh80LjHVKeLIuLkS9',\n",
    "    \n",
    "\n",
    "}\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "a9298bea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.832a536d7e38a4339fe60f8822b0bbc8.2592000.1652284919.282335-25947206'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.json()['access_token']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "7033ff61",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.832a536d7e38a4339fe60f8822b0bbc8.2592000.1652284919.282335-25947206'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "luochen_AT = response.json()['access_token']\n",
    "luochen_AT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f5590db6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result_num': 5, 'result': [{'score': 0.8277347, 'name': '辣椒'}, {'score': 0.12774225, 'name': '红尖椒'}, {'score': 0.023597963, 'name': '尖椒'}, {'score': 0.007160831, 'name': '青辣椒'}, {'score': 0.0039826916, 'name': '朝天椒'}], 'log_id': 1513547922480525079}\n"
     ]
    }
   ],
   "source": [
    "## 01\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "果蔬识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('lj.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "payload={\n",
    "    'access_token':luochen_AT,\n",
    "    'image':img,\n",
    "    'baike_num':5,\n",
    "    \"top_num\":5\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2c6dd61",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4675ded3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "269fb50c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "07b99310",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': {'wineNameCn': '', 'hasdetail': 0}, 'log_id': 1513547932483570719}\n"
     ]
    }
   ],
   "source": [
    "##02 \n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "红酒识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/redwine\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('hj.PNG', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "payload={\n",
    "    'access_token':luochen_AT,\n",
    "    'image':img,\n",
    "    'baike_num':5,\n",
    "    \"top_num\":5\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c510df2b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a80a3bf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28bf0563",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
